package com.jman.announcement.controller;

import cn.hutool.core.bean.BeanUtil;
import com.jman.announcement.domain.Announcement;
import com.jman.announcement.dto.AnnouncementDTO;
import com.jman.announcement.service.impl.AnnouncementServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/announcement")
public class AnnouncementController {
    @Resource
    private AnnouncementServiceImpl announcementService;

    @GetMapping("/show")
    public Announcement getById(@RequestParam Integer id){
        return announcementService.getById(id);
    }

    @GetMapping("/parts")
    public List<AnnouncementDTO> getParts(){
        List<Announcement> announcements = announcementService.list();
        return BeanUtil.copyToList(announcements, AnnouncementDTO.class);
    }

    @PostMapping("/saveInfo")
    public Boolean saveInfo(@RequestBody Announcement announcement){
        return announcementService.save(announcement);
    }

    @GetMapping("/getAll")
    public List<Announcement> getAll(){
        return announcementService.list();
    }

    @DeleteMapping("/del")
    public Boolean deleteById(@RequestParam Integer id){
        return announcementService.removeById(id);
    }

    @GetMapping("/hello")
    public void sayHello(){
        System.out.println("hello");
    }
}
